package com.jojo.bubble.controller;

import com.jojo.bubble.entity.Shop;
import com.jojo.bubble.service.ShopService;
import com.jojo.bubble.common.domain.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.ObjectUtils;
import com.jojo.bubble.common.enums.JsonResultEnum;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商户表(Shop)表控制层
 *
 * @author jojo
 * @since 2023-08-28 13:49:56
 */
@RestController
@RequestMapping("/admin/shop")
public class ShopController {
    /**
     * 服务对象
     */
    @Resource
    private ShopService shopService;


    @GetMapping("/list")
    public AjaxResult getList(Shop record) {
        List<Shop> shopList = shopService.getList(record);
        return AjaxResult.success(shopList);
    }

    @GetMapping("/info")
    public AjaxResult getInfo(Integer id) {
        Shop shop = shopService.getInfo(id);
        return AjaxResult.success(shop);
    }

    @PostMapping("/insert")
    public AjaxResult insert(Shop record) {
        shopService.insert(record);
        return AjaxResult.success();
    }

    @PostMapping("/update")
    public AjaxResult update(Shop record) {
        Shop shop = shopService.getInfo(record.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return AjaxResult.error(JsonResultEnum.RECORD_NULL);
        }
        shopService.update(record);
        return AjaxResult.success();
    }

    @PostMapping("/delete")
    public AjaxResult delete(int id) {
        shopService.delete(id);
        return AjaxResult.success();
    }
}

